package com.cn.thread;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author hels
 * @version 1.0
 * @date 2022/3/8 10:41
 */
public class ThreadPoolDemo2 {
    public static void main(String[] args) {
        // https://www.jianshu.com/p/f030aa5d7a28
        // LinkedBlockingQueue（无界阻塞队列）如果任务提交速度大于任务处理速度，会造成队列大量阻塞。OOM，FixedThreadPool任务执行无序
        ExecutorService service = Executors.newFixedThreadPool(2);
        

        Callable myCallable = new MyCallable();

        service.submit(myCallable);
        service.submit(myCallable);
        service.submit(myCallable);

        service.shutdown();

    }
}


class MyCallable implements Callable<Object>{

    @Override
    public Object call() throws Exception {
        System.out.println(Thread.currentThread().getName() + "来了一个教练");
        Thread.sleep(2000);
        System.out.println(Thread.currentThread().getName() + "教练走了");
        return null;
    }
}


